package com.mod.reanimator 
{
	import com.calefk.core.EntitySimple;
	import com.calefk.core.Project;
	import com.calefk.util.Generic;
	import com.calefk.util.helper;
	import flash.display.MovieClip;
	import com.mod.Global;
	
	/**
	 * ...
	 * @author authorX
	 */
	public class BarVillager extends EntitySimple 
	{
		public static  var MAX_COUNTER:int = 260;
		public var myCounter:int;
		private var speedMoving:Number = 0.2;
		private var myVillager:BaseVillager;
		private var _actualVillagerState:int;
		public function BarVillager(canvas:MovieClip, nameClip:String = null, px:Number = 0, py:Number = 0, project:Project=null, villa:BaseVillager=null) 
		{
			super(canvas, nameClip, px, py,project);
			myCounter = helper.randomInterval(100, 200);
			mClip.limit_mc.x = myCounter;
			myVillager = villa;
		}
		public override function update(dt:int):void
		{
			if (mClip.filler_mc.x <= MAX_COUNTER)
			{
				mClip.filler_mc.x += speedMoving * dt;
				if (Generic.verifyInterval(myCounter, mClip.filler_mc.x, 0))	
				{
					actualVillagerState = BaseVillager.EXPLODING;
				}else
				if (Generic.verifyInterval(myCounter + 25, mClip.filler_mc.x, myCounter))
				{
					actualVillagerState = BaseVillager.REVIVING;
				}else if (Generic.verifyInterval(MAX_COUNTER,mClip.filler_mc.x,myCounter+25))
				{
					actualVillagerState = BaseVillager.EXPLODING;
				}else if (mClip.filler_mc.x > MAX_COUNTER)
				{
					actualVillagerState = BaseVillager.EXPLODING;
					mClip.filler_mc.x = 0;
					speedMoving += 0.05;
				}
			}
		}
		
		public function get actualVillagerState():int 
		{
			return _actualVillagerState;
		}
		
		public function set actualVillagerState(value:int):void 
		{
			_actualVillagerState = value;
		}
		
	}

}